import http from "@/config/request";

/** 首页获取文章列表 */
export const homeGetArticleList = (params) => {
    return new Promise((resolve, reject) => {
        http.get(`/cms/article-detail/page`, {params}).then((res) => {
            resolve(res);
        });
    });
};

/** 时间轴 */
export const blogTimelineGetArticleList = (params) => {
    return new Promise((resolve, reject) => {
        http.get(`/cms/article-detail/blogTimelineGetArticleList`, {params}).then((res) => {
            resolve(res);
        });
    });
};

/** 根据文章id获取推荐文章*/
export const getRecommendArticleById = (id) => {
    return new Promise((resolve, reject) => {
        http.get(`/cms/article-detail/getRecommendArticleById/${id}`, {}).then((res) => {
            resolve(res);
        });
    });
};

/** 根据文章id获取文章详情*/
export const getArticleById = (id) => {
    return new Promise((resolve, reject) => {
        http.get(`/cms/article-detail/get?id=${id}`, {}).then((res) => {
            resolve(res);
        });
    });
};

/** 获取热门文章*/
export const getHotArticle = () => {
    return new Promise((resolve, reject) => {
        http.get("/article/getHotArticle", {}).then((res) => {
            resolve(res);
        });
    });
};

/** 根据文章内容搜索文章*/
export const getArticleByContent = (content) => {
    return new Promise((resolve, reject) => {
        http.get("/article/getArticleListByContent/" + content, {}).then((res) => {
            resolve(res);
        });
    });
};

/** 文章点赞 */
export const articleLike = (id) => {
    return new Promise((resolve, reject) => {
        http.put("/article/like/" + id, {}).then((res) => {
            resolve(res);
        });
    });
};

/** 取消文章点赞 */
export const cancelArticleLike = (id) => {
    return new Promise((resolve, reject) => {
        http.put("/article/cancelLike/" + id, {}).then((res) => {
            resolve(res);
        });
    });
};

/** 文章增加阅读时长 */
export const readingDuration = (articleId, beginTime, endTime) => {
    return new Promise((resolve, reject) => {
        http.post(`/cms/article-detail/addReadingDuration`, {articleId, beginTime, endTime}).then((res) => {
            resolve(res);
        });
    });
};
